#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>

#define PORT_SERV 8888
#define BUFF_LEN  256

void start_server()
{
    int s ;
    struct sockaddr_in addr_serv , addr_cle;

    s = socket(AF_INET , SOCK_DGRAM , IPPROTO_UDP);
    memset(&addr_serv , 0 , sizeof(addr_serv));
    addr_serv.sin_family = AF_INET;
    addr_serv.sin_addr.s_addr = htonl(INADDR_ANY);
    addr_serv.sin_port = htons(PORT_SERV);

    bind(s , (struct sockaddr*)&addr_serv , sizeof(addr_serv));

    int n;

    char buffer[BUFF_LEN];
    int len;
    while(1)
    {
        len = sizeof(addr_cle);
        n = recvfrom(s , buffer , BUFF_LEN , 0 , &addr_cle ,&len);
        if(n >0 )
        {
            printf(" recv msg is %s \n", buffer);
        }
        sendto(s , buffer , n , 0 , &addr_cle , len);
   }
}
